package com.bjdd.jdy.ui.setting;

import com.bjdd.jdy.Constant;
import com.bjdd.jdy.util.JumpUtil;
import com.bjdd.jdy.util.L;
import com.bjdd.jdy.util.SpUtil;

import java.util.Set;

import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;

/**
 * Created by Administrator on 2017/5/8.
 */

public class SettingPresenter extends SettingContract.Presenter {
    @Override
    public void onStart() {
        if (SpUtil.getUser() == null || SpUtil.getUser().equals("") || SpUtil.getUser().getCarrierId() == null) {
            JumpUtil.toLogin(context);
            return;
        }
    }
    @Override
    void setAlias(String alias){
        showLoadingDialog(false);
        Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                L.d("开始设置别名："+alias);
                JPushInterface.setAlias(context, alias, new TagAliasCallback() {
                    @Override
                    public void gotResult(int i, String s, Set<String> set) {

                        view.setAliasBack(i);
                        subscriber.onCompleted();
                    }
                });
            }
        }).subscribe(new Observer<String>() {
            @Override
            public void onCompleted() {
                L.d("线程结束");
                hideLoadingDialog();
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(String s) {

            }
        });
    }
}
